package com.micro.frog.acct.rest;

import com.micro.frog.acct.entity.DictClass;
import com.micro.frog.acct.service.DictClassService;
import com.micro.frog.core.common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author :  ljh
 * @date : 2018/4/11
 **/
@RestController
@RequestMapping("/rbac/dict/class")
public class DictClassController {

    @Autowired
    DictClassService dictClassService;
    /**
     * 字典类型接口类
     * @return
     */
    @GetMapping(value = "/all")
    public Result all(){
        Result result = new Result();
        try{
            result.setFlag(true);
            result.setMsg("成功");
            result.setData(dictClassService.list(null));
        }catch (Exception e){
            result.setFlag(false);
            result.setMsg("系统异常");
            e.printStackTrace();
        }
        return result;
    }

    @PostMapping("/add")
    public Result add(DictClass dictClass) {
        Result result = new Result();
        try{
            dictClassService.add(dictClass);
            result.setFlag(true);
            result.setMsg("新增成功");
        }catch (Exception e){
            result.setFlag(false);
            result.setMsg("新增失败");
            e.printStackTrace();
        }
        return result;
    }

    @PostMapping("/delete")
    public Result delete(Integer id) {
        Result result = new Result();
        try{
            dictClassService.delete(id);
            result.setFlag(true);
            result.setMsg("删除成功");
        }catch (Exception e){
            result.setFlag(false);
            result.setMsg("删除失败");
        }
        return result;
    }

    @PostMapping("/update")
    public Result update(DictClass dictClass) {
        Result result = new Result();
        try{
            dictClassService.update(dictClass);
            result.setFlag(true);
            result.setMsg("修改成功");
        }catch (Exception e){
            result.setFlag(false);
            result.setMsg("修改失败");
        }
        return result;
    }
}
